unit MainView;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, Contnrs, ComCtrls, Tabs,
  StockCodePool, StrUtils, SelectDataDao, StockDataBlockPool, StockParamCollect,
  DataAnalyzeThread, xmldom, XMLIntf, msxmldom, XMLDoc;

type
  TAnalyzeView = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    ListBox1: TListBox;
    Button1: TButton;
    ProgressBar1: TProgressBar;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Label4: TLabel;
    TabSheet4: TTabSheet;
    Button2: TButton;
    Button3: TButton;
    ProgressBar2: TProgressBar;
    ListBox2: TListBox;
    Button4: TButton;
    Button5: TButton;
    ProgressBar3: TProgressBar;
    ListBox3: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    CodePool: TStockCodePool;
    pList: TStringList;
    SelectDataDao: TSelectDataDao;
    c: TStockTotalParam;
      pool: TStockDataBolocPool;
    procedure DataProvideComplete(Sender: TObject);
  public
    { Public declarations }
  end;

var
  AnalyzeView: TAnalyzeView;

implementation

uses DataPickThread, StockDataDAO, Log4D, DataBlockProvideThread,
  StockSelectThread;

{$R *.dfm}

procedure TAnalyzeView.Button1Click(Sender: TObject);
var
  PickThread : TDataPick;
  i:Integer;
begin
    TLog4D.getInstance.SetLogCon(ListBox1.Items);
    SelectDataDao.CreateAnalyzeTable;
    for i := 0 to StrToInt(Edit4.Text) - 1 do
    begin
      PickThread := TDataPick.Create(true,CodePool);
      PickThread.AnalyzeDayCount := StrToInt(Edit2.Text);
      PickThread.TargetDayCount := StrToInt(Edit3.Text);
      PickThread.MaxRisePercentage := StrToInt(Edit1.Text);
      PickThread.MustSun := CheckBox1.Checked;
      PickThread.Start;
    end;
end;

procedure TAnalyzeView.Button2Click(Sender: TObject);
begin
  SelectDataDao.CreateStockBaseData;
end;

procedure TAnalyzeView.Button3Click(Sender: TObject);
var

  StockDataDao: TStockDataDAO;

  S: String;
  i: Integer;

begin
  TLog4D.getInstance.SetLogCon(ListBox2.Items);


  TDataBlockProvide.Create(false,pool,pList[0]);

  pList.Delete(0);

  TDataBlockProvide.Create(false,pool,pList[0]);
  pList.Delete(0);

  Sleep(100000);
  for i := 0 to 40 do
    TDataAnalyze.Create(false,pool,c);

end;

procedure TAnalyzeView.Button4Click(Sender: TObject);
begin
  c.SaveToFile('c:\stock_param.xml');
end;

procedure TAnalyzeView.Button5Click(Sender: TObject);
var
  i:Integer;
  p: TStockTotalParam;
begin
    TLog4D.getInstance.SetLogCon(ListBox3.Items);
    CodePool.setProgressBar(ProgressBar3);

    p := TStockTotalParam.Create;
    p.LoadFromFile('c:\stock_param.xml');
   // ShowMessage(p.Get('30Day').ToString);
   // ShowMessage(p.Get('30Day').Get('AVGOpenPer').ToString);
    for i := 0 to 0 do
    begin
      TStockSelect.Create(false,CodePool,p);
    end;
end;

procedure TAnalyzeView.DataProvideComplete(Sender: TObject);
begin
  if pList.Count > 0 then
  begin
    TDataBlockProvide.Create(false,pool,pList[0]);
    pList.Delete(0);
  end;
end;

procedure TAnalyzeView.FormCreate(Sender: TObject);
var
  StockDataDao: TStockDataDAO;
begin
  SelectDataDao := TSelectDataDao.Create('root','5257mq','money3','127.0.0.1');
  StockDataDao := TStockDataDAO.Create('root','5257mq','money3','127.0.0.1');
  c:= TStockTotalParam.Create;
  try
    CodePool := TStockCodePool.Create(StockDataDao.GetAllStockInfo);
    CodePool.setProgressBar(ProgressBar1);
    pool := TStockDataBolocPool.Create(StockDataDao.GetBlockRecordCount);
    pool.setProgressBar(ProgressBar2);
    pList :=  StockDataDao.GetAllBlockTableName;
  finally
    StockDataDao.Free;
  end;

end;

procedure TAnalyzeView.FormDestroy(Sender: TObject);
begin
  CodePool.Free;
  SelectDataDao.Free;
  pList.Free;
end;

end.
